<?php
class Core_Data_Mappers_Expertises extends Core_Data_Mappers_Abstract {
	protected $_modelclass = 'Core_Data_Models_Expertises';
	protected $_map = array("Id"=>"id","Name"=>"name","Category"=>"categoryname");
	protected $_businessclass = "Core_Business_Expertises";
	
	public function find($id) {
		if(is_array($id))
			$filter = array("id in (?)"=>$id);
		else 
			$filter = array("id = ?"=>$id);
		$data = $this->getDbTable()->fetchAll($filter);
		$out = array();
		if(count($data)>0) {
			foreach ($data as $row) {
				$out[]=$this->map($row);	
			}
			return count($out)==1 ? current($out) : $out ;
		}
		else 
			return null;
	}
	
	public function exists($object) {
		if ($this->find($object->Id))
			return TRUE;
		return FALSE;
	}
	
	public function add($object) {
		if(!$this->exists($object)) {
			$data = $this->reversemap($object);
			unset($data['id']);
			$id = $this->getDbTable()->insert($data);
			$object->Id = $id;
		}	
	}
	
	public function edit($object) {
		if($this->exists($object)) {
			$data = $this->reversemap($object);
			unset($data['id']);
			$this->getDbTable()->update($data,array("id = ?"=>$object->Id));
		}	
	}
	
}
?>